package com.logos.ruralrevitalization.service.impl;

import com.logos.ruralrevitalization.entity.OrderProductMapping;
import com.logos.ruralrevitalization.mapper.OrderProductMappingMapper;
import com.logos.ruralrevitalization.service.OrderProductMappingService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 订单农户关系表(OrderProductMapping)表服务实现类
 *
 * @author rose
 * @since 2025-04-01 12:49:11
 */
@Service("orderProductMappingService")
public class OrderProductMappingServiceImpl implements OrderProductMappingService {
    @Resource
    private OrderProductMappingMapper orderProductMappingMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public OrderProductMapping queryById(Long id) {
        return this.orderProductMappingMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param orderProductMapping 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<OrderProductMapping> queryByPage(OrderProductMapping orderProductMapping, PageRequest pageRequest) {
        long total = this.orderProductMappingMapper.count(orderProductMapping);
        return new PageImpl<>(this.orderProductMappingMapper.queryAllByLimit(orderProductMapping, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param orderProductMapping 实例对象
     * @return 实例对象
     */
    @Override
    public OrderProductMapping insert(OrderProductMapping orderProductMapping) {
        this.orderProductMappingMapper.insert(orderProductMapping);
        return orderProductMapping;
    }

    /**
     * 修改数据
     *
     * @param orderProductMapping 实例对象
     * @return 实例对象
     */
    @Override
    public OrderProductMapping update(OrderProductMapping orderProductMapping) {
        this.orderProductMappingMapper.update(orderProductMapping);
        return this.queryById(orderProductMapping.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.orderProductMappingMapper.deleteById(id) > 0;
    }
}
